//https://leetcode.cn/problems/jump-game-iii/submissions/574447973/

class Solution {
public:
    bool canReach(vector<int>& arr, int start) {
        const int N = 5e4 + 10;
        bool vis[N] = { 0 };
        int n = arr.size();

        queue<int> q;
        q.push(start);
        vis[start] = true;
        while (q.size())
        {
            int now = q.front();
            q.pop();
            int x1 = now - arr[now];
            int x2 = now + arr[now];
            if (x1 >= 0 && !vis[x1])
            {
                vis[x1] = true;
                q.push(x1);
            }
            if (x2 < n && !vis[x2])
            {
                vis[x2] = true;
                q.push(x2);
            }
        }
        for (int i = 0; i < n; i++)
        {
            if (!arr[i] && vis[i])return true;
        }
        return false;
    }
};